﻿namespace Cos.Core.Attributes
{
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.InterceptionExtension;

    public abstract class InterceptorBaseAttribute : HandlerAttribute
    {
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            var handler = new InterceptorDefaultCallHandler(this.Order);

            handler.Error += this.OnError;
            handler.Executed += this.OnExecuted;
            handler.Executing += this.OnExecuting;

            return handler;
        }

        public virtual void OnExecuting(object sender, InterceptorExecutingContextEventArg e)
        {
        }

        public virtual void OnExecuted(object sender, InterceptorExecutedContextEventArg e)
        {
        }

        public virtual void OnError(object sender, InterceptorErrorContextEventArg e)
        {
        }
    }
}
